package com.sansan.qiangji.service.impl.warehouse;

import com.sansan.qiangji.entity.warehouse.TaskLog;
import com.sansan.qiangji.mapper.warehouse.TaskLogMapper;
import com.sansan.qiangji.service.inter.warehouse.TaskLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
@Slf4j
public class TaskLogServiceImpl implements TaskLogService {
    private TaskLogMapper taskLogMapper;

    @Resource
    public void setTaskLogMapper(TaskLogMapper taskLogMapper){
        this.taskLogMapper = taskLogMapper;
    }

    @Override
    public int addTaskLog(TaskLog taskLog) {
        return taskLogMapper.addTaskLog(taskLog);
    }

    @Override
    public List<TaskLog> findByStackerTaskCode(String stackerTaskCode) {
        return taskLogMapper.findByStackerTaskCode(stackerTaskCode);
    }

    @Override
    public void log(String stackerTaskCode, String stackerName, String taskLogInfo) {
        TaskLog taskLog = new TaskLog();
        taskLog.setStackerTaskCode(stackerTaskCode);
        taskLog.setStackerName(stackerName);
        taskLog.setTaskLogInfo(taskLogInfo);
        Date date = new Date();
        taskLog.setTaskLogTime(new Date());
        int row = addTaskLog(taskLog);
        if (row == 0){
            log.error("添加任务日志失败，stackerTaskCode = {}", stackerTaskCode);
        }
    }

    @Override
    public int deleteAll() {
        return taskLogMapper.deleteAll();
    }

    @Override
    public int deleteByStackerName(String stackerName) {
        return taskLogMapper.deleteByStackerName(stackerName);
    }
}
